package java9_22.Test1;

import java.io.*;
import java.net.Socket;
import java.text.SimpleDateFormat;
import java.util.Date;

public class Weather1 extends Thread {
    private Socket s;

    public Weather1(Socket s) {
        this.s = s;
    }

    @Override
    public void run() {
        System.out.println(s+"连接上了");
        BufferedReader b=null;
        try {
            InputStream i = s.getInputStream();
            OutputStream o = s.getOutputStream();
             b=new BufferedReader(new InputStreamReader(i));
            PrintWriter p=new PrintWriter(o);
            SimpleDateFormat s=new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
            while (true){
                Date d=new Date();
                p.println("1:查询天气 2:查询风力 3:查询PM2.5 4:查询湿度 5:退出");
                p.flush();
                String s1 = b.readLine();
                if (s1==null||s1.length()==0){
                    break;
                }else {
                    switch (s1){
                        case "1":
                            p.println("晴天"+s.format(d));
                            continue;
                        case "2":
                            p.println("风力十级大风"+s.format(d));
                            continue;
                        case "3":
                            p.println("PM：150  "+s.format(d));
                         continue;
                        case "4":
                            p.println("湿度：湿度非常大"+s.format(d));
                            continue;
                        case "5":
                            p.println("退出成功");
                            break;
                            default:
                                p.println("请输入正确的数字");
                    }
                }
            }
        } catch (IOException e) {
            e.printStackTrace();
        }finally {
            try {
                b.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }
}
